package com.example.academicsystem.server.controller.admin;

import com.example.academicsystem.pojo.dto.StudentDto;
import com.example.academicsystem.pojo.dto.StudentInsertDto;
import com.example.academicsystem.pojo.dto.StudentUpdateDto;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.result.Result;
import com.example.academicsystem.server.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/student")
@Slf4j
public class AdminStudentController {

    @Autowired
    private AdminService adminService;

    /**
    * 分页查询学生信息（所有、根据学号查询，根据姓名查询）
    * */
    @PostMapping("/page")
    public Result<PageResult> studentPageQuery(@RequestBody StudentDto studentDto){
        log.info("studentPageQuery");
        PageResult pageResult = adminService.studentPageQuery(studentDto);
        return Result.success(pageResult);
    }

    /**
     * 删除学生（by student_id）同时将course_student数据删除
     * */
    @DeleteMapping("/delete")
    public Result studentDelteById(@RequestParam("id") String studentId){
        log.info("studentDelteById:"+studentId);
        adminService.studentDelteById(studentId);
        return Result.success();
    }

    /**
     * 删除course_student by studentId
    * */
    @DeleteMapping("/delete/course")
    public Result courseStudentDeleteById(@RequestParam("id") String studentId){
        log.info("courseStudentDeleteById:"+studentId);
        adminService.courseStudentDeleteById(studentId);
        return Result.success();
    }
    /**
     * 新增student
     * */
    @PostMapping("/insert")
    public Result studentInsert(@RequestBody StudentInsertDto studentInsertDto){
        log.info("studentInsert");
        adminService.studentInsert(studentInsertDto);
        return Result.success();
    }
    /**
     * 修改student by id
     * */
    @PutMapping("/update")
    public Result studentUpdateById(@RequestBody StudentUpdateDto studentUpdateDto){
        log.info("studentUpdate");
        adminService.studentUpdateById(studentUpdateDto);
        return Result.success();
    }

}
